package com.example.joewang.surfaceviewmotion.model;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by simplecc on 2017/10/20.
 */


public class SnowManager {

    private static final int COUNT = 100;
    private List<Snow> mSnowContents = new ArrayList<>();
    private static SnowManager sInstance;

    public static SnowManager getInstance(Context context) {
        if (sInstance == null) {
            sInstance = new SnowManager();
            WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            DisplayMetrics outMetircs = new DisplayMetrics();
            wm.getDefaultDisplay().getMetrics(outMetircs);
            int w = outMetircs.widthPixels;
            int h = outMetircs.heightPixels;
            Random xRandom = new Random();
            Random yRandom = new Random();
            for (int i = 0; i < COUNT; i++) {
                Snow snow = new Snow(xRandom.nextInt(w), yRandom.nextInt(h));
                snow.setmDirection(0);
                snow.setmDropSpeed(Snow.getRandomSpeed());
                snow.setmAngle(Snow.getRandomAngle());
                snow.setBounds(w, h);
                sInstance.addSnow(snow);
            }
        }
        return sInstance;
    }


    public void addSnow(Snow snow) {
        mSnowContents.add(snow);
    }

    public List<Snow> getAllSnows() {
        return mSnowContents;
    }

}
